<template>
  <div class="user-container">
    <div class="user-content">
      <Menu :active-name="activeName()" :open-names="openName()">
        <MenuItem name="publish" v-if="checkVerified()" id="publish">
          <Button
            long
            type="primary"
            size="large"
            icon="md-add"
            to="publish"
            :disabled="this.$route.name == 'publish' ? true:false"
          >发布作品</Button>
        </MenuItem>
        <Submenu name="infoManagement">
          <template slot="title">
            <Icon type="md-person" />信息管理
          </template>
          <MenuItem name="profile" to="profile">个人信息</MenuItem>
          <MenuItem name="shop" to="shop" v-if="checkVerified()">匠人信息</MenuItem>
          <MenuItem name="pwd" to="password_reset">修改密码</MenuItem>
        </Submenu>
        <Submenu name="noteManagement">
          <template slot="title">
            <Icon type="md-quote" />手记管理
          </template>
          <MenuItem name="note" to="note">手记管理</MenuItem>
          <MenuItem name="note_comments" to="note_comments">评论管理</MenuItem>
        </Submenu>
        <Submenu name="blogManagement" v-if="checkVerified()">
          <template slot="title">
            <Icon type="ios-paper" />帖子管理
          </template>
          <MenuItem name="blog" to="blog">文章管理</MenuItem>
          <MenuItem name="blog_comments" to="blog_comments">评论管理</MenuItem>
        </Submenu>
        <Submenu name="orderManagement" v-if="checkVerified()">
          <template slot="title">
            <Icon type="ios-paper" />订单管理
          </template>
          <MenuItem name="order_buyer" to="order_management?roll=buyer">我买到的</MenuItem>
          <MenuItem name="order_seller" to="order_management?roll=seller">我卖出的</MenuItem>
        </Submenu>
        <MenuItem name="goods" to="goods_management?type=goods" v-if="checkVerified()">
          <Icon type="md-shirt" />商品管理
        </MenuItem>
        <MenuItem name="order" to="order_management?roll=buyer" v-if="!checkVerified()">
          <Icon type="md-list-box" />我的订单
        </MenuItem>
        <MenuItem name="follow">
          <Icon type="md-people" />我的关注
        </MenuItem>
        <MenuItem name="fans">
          <Icon type="md-happy" />我的粉丝
        </MenuItem>
      </Menu>
      <router-view />
    </div>
  </div>
</template>

<script>
import { AuthCheck } from "../utils/mixin";
export default {
  name: "user",
  mixins: [AuthCheck],
  watch: {
    $route() {
      this.activeName();
      this.openName();
    }
  },
  methods: {
    activeName() {
      switch (this.$route.name) {
        case "publish":
          return "publish";
        case "profile":
          return "profile";
        case "shop":
          return "shop";
        case "password_reset":
          return "pwd";
        case "note":
          return "note";
        case "note_comments":
          return "note_comments";
        case "blog":
          return "blog";
        case "blog_comments":
          return "blog_comments";
        case "goods_management":
          return "goods";
        case "order_management":
          return "order";

        default:
          return "profile";
      }
    },
    openName() {
      switch (this.$route.name) {
        case "profile":
          return ["infoManagement"];
        case "note":
          return ["noteManagement"];
        case "note_comments":
          return ["noteManagement"];
        case "blog" :
          return ["blogManagement"];
        case 'blog_comments':
          return ["blogManagement"];
        case 'order_management':
          return ["orderManagement"];

        default:
          return [];
      }
    }
  }
};
</script>
